<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    protected $primaryKey = 'id';

    protected $fillable = [
        'user_nu',                  #用户编号
        'username',                 #登录账户
        'email',                    #邮箱
        'nick_name',                #用户id
        'avatar',                   #头像
        'phone',                    #手机号
        'password',                 #密码
        'role',                     #角色 customer:顾客,seller:商家
        'login_status',             #登录状态 forbidden, normal
        'gag_status',               #禁言状态 forbidden, normal
        'gag_duration',             #禁言时长 分钟
    ];

    protected $hidden = [
        'password',
    ];

    const FORBIDDEN = 'forbidden';

    const NORMAL = 'normal';

    static $LOGIN_STATUS_MAP = [
        self::FORBIDDEN => '凍結',
        self::NORMAL => '正常',

    ];

    static $GAG_STATUS_MAP = [
        self::FORBIDDEN => '禁言',
        self::NORMAL => '正常',
    ];

    const CUSTOMER = 'customer';

    const SELLER = 'seller';

    static $ROLE_MAP = [
        self::CUSTOMER => '顧客',
        self::SELLER => '商家',
    ];

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }

    public function wallet()
    {
        return $this->hasOne(Wallet::class, 'user_id', 'id')->withDefault();
    }

    public function data()
    {
        return $this->hasOne(UserData::class, 'user_id', 'id')->withDefault();
    }

    public function shop()
    {
        return $this->hasOne(Shop::class, 'user_id', 'id')->withDefault();
    }

    public function comments()
    {
        return $this->morphMany(Comment::class, 'object');
    }

    public function messages()
    {
        return $this->hasMany(Message::class, 'user_id', 'id');
    }

    public function payment()
    {
        return $this->hasMany(Payment::class, 'user_id', 'id');
    }

    public function logBalance()
    {
        return $this->hasMany(LogBalance::class, 'user_id', 'id');
    }

    public function pictures()
    {
        return $this->hasMany(Picture::class, 'user_id', 'id');
    }
}
